//
//  LoggerEvent.m
//  GaCameraViewProject
//
//  Created by GikkiAres on 2020/4/6.
//  Copyright © 2020 GikkiAres. All rights reserved.
//

#import "JsLogEvent.h"
#import "JsTimeManager.h"

@implementation JsLogEvent

+ (JsLogEvent *)eventWithLogLevel:(JsLogLevel)logLevel logTarget:(JsLogTargetOption)logTarget context:(NSString *)context contentType:(NSString * __nullable)contentType message:(NSString *)message {
	JsLogEvent * event = [JsLogEvent new];
	event.logLevel = logLevel;
	event.context = context;
	event.message = message;
	event.logTarget = logTarget;
	event.fullTimeString = [JsTimeManager stdTimeStringForNow];
	event.contentType = contentType;
	return event;
}


/**
 content实行懒加载,可以根据情况进行配置.
 */
- (NSString *)content {
	if(!_content) {
		if(self.plain) {
			_content = self.message;
		}
		else {
			_content = [NSString stringWithFormat:@"[%@] [%@] [%@] [%@]:%@\n",self.fullTimeString, [self logLevelString] ,self.context,self.contentType,self.message];
		}
	}
	return _content;
}

- (NSString *)contentType {
	if(_contentType) {
		return _contentType;
	}
	return @"";
}

- (NSString *)message {
	if(_message) {
		return _message;
	}
	return @"";
}

- (NSString *)logLevelString {
	switch (self.logLevel) {
		case JsLogLevelVerbose:
			return @"Verbose";
		case JsLogLevelInfo:
			return @"Info";
		case JsLogLevelDebug:
			return @"Debug";
		case JsLogLevelWarn:
			return @"Warn";
		case JsLogLevelError:
			return @"Error";
		case JsLogLevelFatal:
			return @"Fatal";
		default:
			return @"";
	}
}






@end
